package com.you.atlas.web.place.module.screen;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.service.form.Group;
import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.FormGroup;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.you.atlas.biz.place.service.NoteItemQueryService;
import com.you.atlas.biz.place.service.NotePhotoService;
import com.you.atlas.biz.place.service.NoteQueryService;
import com.you.place.dal.dao.dataobject.NoteDO;
import com.you.place.dal.dao.dataobject.NoteItemDO;
import com.you.place.dal.dao.dataobject.NotePhotoDO;

public class NoteModify {

    @Autowired
    private NoteQueryService noteQueryService;

    @Autowired
    private NoteItemQueryService  noteItemService;
    
    @Autowired
    private NotePhotoService notePhotoQueryService;

    public void execute(@FormGroup("postNote") Group group, @Param("noteItemId") Long noteItemId, Context context,
                        Navigator navigator) {
        NoteItemDO noteItemDO = noteItemService.find(noteItemId);
        if (noteItemDO == null) {
            navigator.redirectTo("placeModule").withTarget("error.vm");
            return;
        }
        NoteDO noteDO = noteQueryService.find(noteItemDO.getNoteId());
        group.getField("title").setValue(noteDO.getTitle());
        group.getField("content").setValue(noteItemDO.getContent());
        context.put("noteDO", noteDO);
        
        List<NotePhotoDO>  notePhotoList = notePhotoQueryService.queryNotePhotoList(noteItemId);
        context.put("notePhotoList", notePhotoList);
        
    }
}
